package utils;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @program: ocr_auto_app
 * @description:
 * @author: YB
 * @create: 2022-08-08 14:15
 **/
public class ImgFileUtils {
    /**
     * 存为PNG格式
     */
    public static void saveToFile(BufferedImage subimage, File file) throws IOException {
        ImageIO.write(subimage, "png", file);
    }

    /**
     * 存为PNG格式
     */
    public static void saveAsPNG(BufferedImage subimage, File file) throws IOException {
        ImageIO.write(subimage, "png", file);
    }

    /**
     * 存为JPEG格式图像文件
     */
    public static void saveAsJPEG(BufferedImage subimage, File file) throws IOException {
        ImageIO.write(subimage, "JPEG", file);
    }

    /**
     * 写入一个OutputStream
     */
    public static void write(BufferedImage subimage, OutputStream out) throws IOException {
        ImageIO.write(subimage, "png", out);
    }
}
